package com.hegongda.okcmall.product.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hegongda.common.utils.PageUtils;
import com.hegongda.common.utils.Query;

import com.hegongda.okcmall.product.dao.AttrAttrgroupRelationDao;
import com.hegongda.okcmall.product.entity.AttrAttrgroupRelationEntity;
import com.hegongda.okcmall.product.service.AttrAttrgroupRelationService;
import org.springframework.transaction.annotation.Transactional;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public AttrAttrgroupRelationEntity selectOne(Long attrId) {
        QueryWrapper<AttrAttrgroupRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("attr_id", attrId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Long> getAttrIds(String groupId) {
        return baseMapper.getAttrIdByGroupId(groupId);
    }

    @Override
    @Transactional
    public void deleteRecoder(List<AttrAttrgroupRelationEntity> entities) {
        baseMapper.deleteBatch(entities);
    }

}